import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '首页',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'example' }
    }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/table',
    name: '用户管理',
    meta: { title: '用户管理', icon: 'example' },
    children: [
      {
        path: 'table',
        name: '用户列表',
        component: () => import('@/views/hr/user/list'),
        meta: { title: '用户列表', icon: 'table' }
      },
      {
        path: 'save',
        name: '添加用户',
        component: () => import('@/views/hr/user/save'),
        meta: { title: '添加用户', icon: 'form' }
      },
      {
        path: 'edit/:id',
        name: '编辑用户',
        component: () => import('@/views/hr/user/save'),
        meta: { title: '编辑用户', noCache: true },
        hidden: true
      },
      {
        path: 'detail/:id',
        name: '用户信息',
        component: () => import('@/views/hr/user/detail'),
        meta: { title: '用户信息', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/job',
    component: Layout,
    redirect: '/job/table',
    name: '职位管理',
    meta: { title: '职位管理', icon: 'example' },
    children: [
      {
        path: 'table',
        name: '职位列表',
        component: () => import('@/views/hr/job/list'),
        meta: { title: '职位列表', icon: 'table' }
      },
      {
        path: 'save',
        name: '添加职位',
        component: () => import('@/views/hr/job/save'),
        meta: { title: '添加职位', icon: 'form' }
      },
      {
        path: 'edit/:id',
        name: '编辑职位',
        component: () => import('@/views/hr/job/save'),
        meta: { title: '编辑职位', noCache: true },
        hidden: true
      },
      {
        path: 'register/:id',
        name: '应聘情况',
        component: () => import('@/views/hr/job/register'),
        meta: { title: '应聘情况', noCache: true },
        hidden: true
      },
      {
        path: 'detail/:id',
        name: '职位详情',
        component: () => import('@/views/hr/job/detail'),
        meta: { title: '职位详情', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/unit',
    component: Layout,
    redirect: '/unit/list',
    name: '单位管理',
    meta: { title: '单位管理', icon: 'example' },
    children: [
      {
        path: 'list',
        name: '单位列表',
        component: () => import('@/views/hr/unit/list'),
        meta: { title: '单位列表', icon: 'tree' }
      }]
  },
  {
    path: '/faq',
    component: Layout,
    redirect: '/faq',
    name: 'FAQ',
    children: [{
      path: 'faq',
      name: 'FAQ',
      component: () => import('@/views/hr/faq/faq'),
      meta: { title: 'FAQ', icon: 'example' }
    }]
  },
  {
    path: '/external-link',
    component: Layout,
    name: 'external-link',
    meta: { title: 'external-link', icon: 'example' },
    children: [
      {
        path: 'https://github.com/fighYo/ppmall.git',
        name: 'github',
        meta: { title: 'github', icon: 'github' }
      },
      {
        path: 'https://gitee.com/fighYo/ppmall',
        name: 'gitee',
        meta: { title: 'gitee', icon: 'gitee' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
